﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TargetChooser : Chooser
{
    private static TargetChooser instance;
    public Character character;

    void Awake()
    {
        if (instance != null)
        {
            Destroy(this);
        }
        instance = this;
    }

    void Update()
    {
        
    }

    public static bool IsCloosed()
    {
        return instance.isChoosed;
    }

    public static void ReSet()
    {
        for (int i = 1; i < instance.transform.childCount; i++)
        {
            Destroy(instance.transform.GetChild(i).gameObject);
        }
        instance.isChoosed = false;
    }

    public static void ChooseInTeam(Team team)
    {
        Vector3 position = instance.firstButton.transform.position;
        foreach(Character character in team.characters)
        {
            ChooserButton newButton = GameObject.Instantiate(instance.chooserButtonPrefab,position,instance.chooserButtonPrefab.rotation, instance.transform).GetComponent<ChooserButton>();
            newButton.SetCharacter(character);
            position.y -= instance.buttonSpacing;
        }
    }
    
    public static void ChooseCharacter(Character target)
    {
        instance.isChoosed = true;
        instance.character = target;
    }

    public static void GetChoose(ChooserButton chooserButton)
    {
        instance.isChoosed = true;
        instance.character = chooserButton.character;
    }

    public static Character GetChoosedCharacter()
    {
        return instance.character;
    }

}
